
class MakeDir extends JSCommand {
	
	private static final String cmdName = "mkdir";
	private static final String dirFullError = "Error: Directory %s is full";
	
	public String runCmd(String[] cmdArgs, JSDirectory workDir) {

		String result;
		boolean validArgs = isValidArgs(cmdArgs, workDir);
		
		if (validArgs) {
			
			// Check if there is room for a new folder
			if (workDir.isFull()) {
				result = String.format(dirFullError, workDir.getAddress());
			} else {
				// Create the new directory according to cmdArgs
				JSDirectory newDir = new JSDirectory(cmdArgs[1], workDir);
				workDir.addDirectory(newDir);
				result = "";
			}
		
		} else {
			result = invalidArgsMessage;
		}
		
		return result;
	}
	
	private boolean isValidArgs(String[] cmdArgs, JSDirectory workDir) {
		return (cmdArgs[0] == cmdName &&
				cmdArgs.length == 2);
	}
}
